#include "XmlForm.h"
#include "ui_XmlForm.h"



XmlForm::XmlForm(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::XmlForm)
{
    m_campaign = 0;
    ui->setupUi(this);

    ui->widget->hide();
}


XmlForm::~XmlForm()
{
    delete ui;
}


void XmlForm::setCampaign(Campaign* c)
{
    disconnect(this, SLOT(onChanged()));

    m_campaign = c;
    if (m_campaign.isNull()) return;

    onChanged();

    connect(m_campaign.data(), SIGNAL(sigChanged()), this, SLOT(onChanged()));
}



Campaign* XmlForm::campaign() const
{
    return m_campaign.data();
}



void XmlForm::onChanged()
{
    ui->textEditXml->clear();
    if (m_campaign.isNull())
    {
        ui->textEditXml->setPlainText("Sender not a campaign!");
        return;
    }

    ui->textEditXml->setPlainText(m_campaign->serializedData());
}



void XmlForm::on_pushButton_clicked()
{
    //onChanged();
}

void XmlForm::on_updateButton_clicked()
{
    //m_campaign->setSerializedData(ui->textEditXml->toPlainText());
    //m_campaign->setDirty(true);
}
